<?php 
/*
Engineer: Alex Arey
Updated: 12/04/2011
Description: Displays acceptance and general information of selected internship application
*/
?>

<?php 
	$auth = Zend_Auth::getInstance(); 
	$userID = $auth->getIdentity()->getUID();
	$app = null;
	if($this->application){
		$app = $this->application;
	}
?>
<h3>Application Status:</h3>
<?php if($app && ($this->usertype == 'admin')): ?>
<table>
	<tr>
		<th>Position</th>
		<th>Partner Accepted</th>
		<th>Student Accepted</th>
		<th></th>
	</tr>
	<?php 
		foreach($app->_suggestedpositions as $pos){
			$posmodel = new Application_Model_InternshipQuery();
			$position = $posmodel->selectInternship_ID($pos['POSID']);
			echo '<tr align = "center">';
			echo "<td><a href=". $this->url(array('controller'=>'common', 'action'=>'viewinternshipdetails',
				'posid'=>$pos['POSID'])).">".$posmodel->getPartnerNameForPID($position['POSID'])."-".$position['NAME']."</a></td>";
			echo '<td>';
				if($pos['ACCEPTED']=='c'||$pos['ACCEPTED']=='s'||$pos['ACCEPTED']=='t')
					echo'Accepted';
				else if($pos['ACCEPTED']=='d')
					echo 'Denied';
				else
					echo 'Undecided';
			echo'</td>';
			echo '<td>';
				if($pos['ACCEPTED']=='s')
					echo'Accepted';
				else if($pos['ACCEPTED']=='t')
					echo 'Denied';
				else
					echo 'Undecided';
			echo'</td>';
			echo '<td><a href='.$this->url(array('controller'=>'applications', 'action'=>'delete', 'position'=>$pos['POSID'],
				'application'=>$app->_appID)).'>Remove</a></td>';
			echo '</tr>';
			} 
	?>
	<tr>
		<td colspan = "4" align = "center">
			<a href='
				<?php 
					echo $this->url(array('controller'=>'applications', 'action'=>'add','application'=>$app->_appID));
				?>
				'>Suggest as candidate to another position</a></td>
	</tr>
</table>
<?php endif; ?>
<?php if($app && $this->usertype == 'student'): ?>
<table>
	<tr>
		<th>Position</th>
		<th>Organization Accepted</th>
		<th>Student Accepted</th>
	</tr>
	<?php if($app->_suggestedpositions): ?>
		<?php 
			$freeSpace = true;//student has not yet made a decision
			foreach($app->_suggestedpositions as $pos){
				if($pos['ACCEPTED']=='s')
					$freeSpace = false;
			}
			foreach($app->_suggestedpositions as $pos){
				$cpaccept = false;
				$saccept = false;
				$posmodel = new Application_Model_InternshipQuery();
				$position = $posmodel->selectInternship_ID($pos['POSID']);
				echo '<tr align = "center">';
				echo "<td><a href=". $this->url(array('controller'=>'common', 'action'=>'viewinternshipdetails',
					'posid'=>$pos['POSID'])).">".$position['NAME']."</a></td>";
				echo '<td>';
					if($pos['ACCEPTED']=='c'||$pos['ACCEPTED']=='s'||$pos['ACCEPTED']=='t')
						echo'Accepted';
					else if($pos['ACCEPTED']=='d')
						echo 'Denied';
					else
						echo 'Undecided';
				echo'</td>';
				echo '<td>';
					if($pos['ACCEPTED']=='s'){
						echo'Accepted';
						$saccept = true;
					}
					else if($pos['ACCEPTED']=='t')
						echo 'Turned Down';
					else if($pos['ACCEPTED']=='c'&& $freeSpace)
						echo '<a href='.$this->url(array('controller'=>'applications', 'action'=>'studentdecide', 'position'=>$pos['POSID'],
							'application'=>$app->_appID)).'>Make Decision</a></td>';
					else
						echo 'N/A';
				echo'</td>';
				echo '</tr>';
				} 
		?>
	<?php endif; ?>
<?php if(!$app->_suggestedpositions): ?>
	<tr>
	</tr>
	<tr>
		<td colspan = "3" align = "center">Your application has been submitted and is pending review.</td>
	</tr>
<?php endif; ?>
</table>
<?php endif; ?>

<?php if($app && $this->usertype == 'organization'): ?>
<table>
	<tr>
		<th>Position</th>
		<th>Accepted</th>
		<th>Student Response</th>
	</tr>
	<?php
		$posmodel = new Application_Model_InternshipQuery();
		$pos = $this->position;
		$status = $app->getStatus_Pos($pos['POSID']);
		$freeSpace = ($posmodel->positionsAvailable($pos['POSID'])>0);//partner has not exhausted all granted positions
		echo '<tr align = "center">';
		echo "<td><a href=". $this->url(array('controller'=>'common', 'action'=>'viewinternshipdetails',
				'posid'=>$pos['POSID'])).">".$pos['NAME']."</a></td>";
		echo '<td>';
		if($status=='c'||$status=='s'||$status=='t'){
			echo'Accepted';
		}
		else if($status=='d')
			echo 'Denied';
		else if ($freeSpace)
			echo'<a href='. $this->url(array('controller'=>'applications', 'action'=>'partnerdecide',
				'position'=>$pos['POSID'],'application'=>$app->_appID)).'>Make Decision</a>';
		else
			echo 'N/A';
		echo'</td>';
		echo '<td>';
		if($status=='s'){
			echo'Accepted';
		}
		else if($status=='t')
			echo 'Denied';
		else if($status =='c')
			echo 'Undecided';
		else
			echo 'N/A';
		echo'</td>';
		echo'</tr>';
	?>
</table>
<?php endif; ?>
<?php if($app):?>
<h3>Application Details:</h3>
<dl>
	<dt>Application for Term</dt>
		<dd><?php echo $app->_term ?></dd>
	<dt>Applicant Name:</dt>
		<dd><?php echo $app->_firstName . " " . $app->_midName . " " . $app->_lastName ?></dd>
	<dt>Applicant Email:</dt>
		<dd><?php echo $app->_email ?></dd>
	<dt>Applicant Phone:</dt>
		<dd><?php echo $app->_phone ?></dd>
	<dt>Applicant's Major:</dt>
		<dd><?php echo $app->_major ?></dd>
<!--	<dt>Student Status of Applicant:</dt>
		<dd><?php echo $app->_status ?></dd> -->
	<dt>Applicant's Year:</dt>
		<dd><?php switch($app->_year){
			case 1:
				echo 'First Year';
				break;
			case 2:
				echo 'Sophmore';
				break;
			case 3:
				echo 'Junior';
				break;
			case 4:
				echo 'Senior';
				break;
			}
		 ?></dd>
	<dt>Applicant GPA:</dt>
		<dd><?php echo $app->_gpa ?></dd>
	<dt>Applicant Has Transportation:</dt>
		<dd><?php echo ($app->_transport=='y')? 'Yes':'No'; ?></dd>
	<dt>Applicant's prior experience with APPLES Service-Learning Program:</dt>
		<dd><?php echo $app->_experience ?></dd>
	<dt>Describe a social issue that interests you and explain why: </dt>
		<dd><?php echo $app->_issueText ?></dd>
	<dt>Applicant's Relevant Coursework</dt>
		<dd><?php echo $app->_courseWork ?></dd>
	<dt>Résumé URL</dt>
		<dd><a href="<?php echo $app->_resumeURL ?>" target="_blank"><?php echo $app->_resumeURL ?></a></dd>		
</dl>
<h3>References for this application:</h3>
<table>
	<tr>
		<th>Name</th>
		<th>Phone</th>
		<th>Address</th>
		<th>Relationship</th>
	</tr>
	<?php if($app->_references): ?>
		<?php foreach($app->_references as $r):?>
		<tr align="center">
			<td>
				<?php echo $r['NAME']; ?>
			</td>
			<td>
				<?php echo $r['PHONE']; ?>
			</td>
			<td>
				<?php echo $r['ADDRESS1']; ?><br/>
				<?php if($r['ADDRESS2'] && $r['ADDRESS2']!= "") echo $r['ADDRESS2'].'<br/>'; ?>
				<?php echo $r['CITY']. ",&nbsp;" . $r['STATE'] . "&nbsp;" . $r['ZIP']; ?>
			</td>
			<td>
				<?php echo $r['RELATIONSHIP']; ?>
			</td>
		</tr>
		<?php endforeach; ?>
	<?php endif; ?>
	<?php if(!$app->_references): ?>
		<tr>
			<td colspan="4" align = "center"> No references associated with this application.</td>
		</tr>
	<?php endif; ?>
</table>
<?php endif; ?>
<?php if(!$app): ?>
<h3>This application does not exist or you do not have permission to view it.</h3>
<?php endif; ?>
